<template>
  <div class="container">
    <el-form :inline="true">
      <el-form-item>
        <el-input
          v-model="pageGrid.orderNo"
          placeholder="内部订单号"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-input
          v-model="pageGrid.staffNumber"
          placeholder="员工工号"
        ></el-input>
      </el-form-item>
   
      <el-form-item>
        <el-select v-model="pageGrid.production" placeholder="请选择工艺">
          <el-option
            :label="item"
            :value="item"
            v-for="item in listProduction"
            :key="item"
          ></el-option>
        </el-select>
      </el-form-item>


  <el-form-item>
        <el-date-picker
          v-model="pageGrid.date"
          type="daterange"
          range-separator="至"
          @change="setDate"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-select v-model="pageGrid.status" placeholder="请选择状态">
          <el-option label="加工中" value="0"></el-option>
          <el-option label="已完成" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getData">搜索</el-button>
        <el-button @click="clearSearch">重置</el-button>
        <el-button
          @click="exportList"
          :loading="isExport"
          type="primary"
          icon="el-icon-files"
          >导出</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="isLoading"
      :data="tableData"
      border
      class="table"
      ref="multipleTable"
    >
      <el-table-column
        prop="order_no"
        label="订单号"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="roughSupplier"
        label="供应商代码"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="roughItemNo"
        label="料号"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="compressDown2"
        label="压缩角公差下限2"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="compressUp2"
        label="压缩角公差上限2"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="dingjingDown2"
        label="定经公差下限2"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="dingjingUp2"
        label="定经公差上限2"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="custNo"
        label="客户代码"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="specs"
        label="规格"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="startDate"
        label="日期"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="amount"
        label="数量"
        align="center"
      ></el-table-column>
      <!-- <el-table-column
        prop="startTime"
        label="开始时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="endTime"
        label="结束时间"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="subTime"
        label="工作时间"
        align="center"
      ></el-table-column> -->
      <el-table-column
        prop="staff_number"
        label="工号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="staff_name"
        label="员工"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="production"
        label="工艺"
        align="center"
      ></el-table-column>
      <el-table-column prop="status" label="状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == '0'">加工中</span>
          <span v-if="scope.row.status == '1'">已完成</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageGrid.pageNo"
        :page-sizes="pageSizeArr"
        :page-size="pageGrid.pageSize"
        layout="total, sizes, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import api from "../../../api";
import commonInfo from "@/utils/common";
import { exportInfo } from "@/utils/export";
import host from "@/utils/host";

export default {
  data() {
    return {
      pageSizeArr: commonInfo.pageSizeArr,
      isLoading: false,
      tableData: [],
      total: 0,
      pageGrid: {
        pageNo: 1,
        pageSize: 10,
        orderNo: null,
        date:null,
        staffNumber: null,
        startTime: null,
        endTime: null,
        production: null,
      },
      exportExcelUrl: host.host + "excel/open/staffProductionRecordExport",
      listProduction: [],
      isExport: false,
    };
  },
  created() {
    this.getListProduction();
    this.getData();
  },
  methods: {
      setDate(val) {
      if (val) {
        this.pageGrid.startTime = val[0];
        this.pageGrid.endTime = val[1];
      } else {
        this.pageGrid.startTime = null;
        this.pageGrid.endTime = null;
      }
    },
    getData() {
      this.isLoading = true;
      api
        .getListStaffProductionRecord(this.pageGrid)
        .then((res) => {
          if (res.code === 200) {
            this.tableData = res.totalElement;
            this.total = res.total;
            this.isLoading = false;
          }
        })
        .catch((this.isLoading = false));
    },
    setDate(val) {
      if (val) {
        this.pageGrid.startTime = val[0];
        this.pageGrid.endTime = val[1];
      } else {
        this.pageGrid.startTime = null;
        this.pageGrid.endTime = null;
      }
    },
    getListProduction() {
      api
        .getListProduction()
        .then((res) => {
          this.listProduction = res.data;
        })
        .catch();
    },
    exportList() {
      this.isExport = true;
      let info = {
        method: "GET",
        url: this.exportExcelUrl,
        responseType: "blob",
        type: "excel",
        name: "用工信息",
        params: this.pageGrid,
      };
      exportInfo(info).then((res) => {
        this.isExport = false;
      });
    },
    clearSearch() {
      this.pageGrid = {
        pageNo: 1,
        pageSize: 10,
        orderNo: null,
        staffId: null,
        startTime: null,
        endTime: null,
        production: null,
      };
      this.getData();
    },
    //分页
    handleCurrentChange(val) {
      this.pageGrid.pageNo = val;
      this.getData();
    },
    //分页
    handleSizeChange(val) {
      this.pageGrid.pageSize = val;
      this.getData();
    },
  },
};
</script>

<style scoped lang="less">
</style>
